use crate::service::menu_service::MenuService;

use actix_web::web::Json;
use actix_web::{delete, get, post, put};
use actix_web::{HttpRequest, HttpResponse};
use fast_common::common::api_result::Api;
use fast_common::models::menu::{Menu, MenuVo};

#[post("/new")]
pub async fn new_menu(arg: Json<Menu>, _request: HttpRequest) -> HttpResponse {
    let result = MenuService::add(arg.into_inner()).await;
    return Api::from_rbatis_result(result)
        .await
        .to_response_of_json()
        .await;
}

#[get("/list")]
pub async fn list_menu(arg: Json<MenuVo>, _req: HttpRequest) -> HttpResponse {
    let result = MenuService::list(arg.into_inner()).await;
    return Api::from_rbatis_result(result)
        .await
        .to_response_of_json()
        .await;
}

#[put("/update")]
pub async fn update_menu(arg: Json<Menu>, _request: HttpRequest) -> HttpResponse {
    let result = MenuService::update(arg.into_inner()).await;
    return Api::from_rbatis_result(result)
        .await
        .to_response_of_json()
        .await;
}

#[delete("/delete")]
pub async fn delete_menu(arg: Json<Menu>) -> HttpResponse {
    let result = MenuService::delete(arg.into_inner()).await;
    return Api::from_rbatis_result(result)
        .await
        .to_response_of_json()
        .await;
}
